package com.fyzk.activity.lottery.jc.football.pop;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.tyjc.lottery.R;


public class JCZQSelectPlayMethodPop extends PopupWindow implements OnCheckedChangeListener {

    private LinearLayout llNoDan;
    private CheckBox spf_zq, bf_zq, zjq_zq, bqc_zq, hg_zq;
    private CheckBox spf_zq_d, bf_zq_d, zjq_zq_d, bqc_zq_d;

    public JCZQSelectPlayMethodPop(Context context, int width, int height, boolean isDanGuanInto) {
        super(width, height);
        View view = View.inflate(context, R.layout.layout_selectplaymethod_jczq, null);
        this.setContentView(view);
        initView(view, isDanGuanInto);
        this.setOutsideTouchable(true);
        this.setBackgroundDrawable(context.getResources().getDrawable(R.color.transparent));
        // 设置此参数获得焦点，否则无法点击
        this.setFocusable(true);
    }

    private void initView(View view, boolean isDanGuanInto) {
        llNoDan = (LinearLayout) view.findViewById(R.id.llNoDan);
        spf_zq = (CheckBox) view.findViewById(R.id.cb_selectplaymethod_spf_zq);
        spf_zq_d = (CheckBox) view.findViewById(R.id.cb_selectplaymethod_d_spf_zq);
        zjq_zq = (CheckBox) view.findViewById(R.id.cb_selectplaymethod_zjq_zq);
        bf_zq_d = (CheckBox) view.findViewById(R.id.cb_selectplaymethod_d_zjq_zq);
        bqc_zq = (CheckBox) view.findViewById(R.id.cb_selectplaymethod_bqc_zq);
        zjq_zq_d = (CheckBox) view.findViewById(R.id.cb_selectplaymethod_d_bqc_zq);
        bf_zq = (CheckBox) view.findViewById(R.id.cb_selectplaymethod_bf_zq);
        bqc_zq_d = (CheckBox) view.findViewById(R.id.cb_selectplaymethod_d_bf_zq);
        hg_zq = (CheckBox) view.findViewById(R.id.cb_selectplaymethod_hg_zq);
        spf_zq.setOnCheckedChangeListener(this);
        spf_zq_d.setOnCheckedChangeListener(this);
        hg_zq.setOnCheckedChangeListener(this);
        zjq_zq.setOnCheckedChangeListener(this);
        zjq_zq_d.setOnCheckedChangeListener(this);
        bqc_zq.setOnCheckedChangeListener(this);
        bqc_zq_d.setOnCheckedChangeListener(this);
        bf_zq.setOnCheckedChangeListener(this);
        bf_zq_d.setOnCheckedChangeListener(this);
        if (isDanGuanInto) {
            spf_zq_d.setChecked(true);
            llNoDan.setVisibility(View.GONE);
        }else{
            hg_zq.setChecked(true);
            llNoDan.setVisibility(View.VISIBLE);
        }
    }

    private void clearChecked() {
        spf_zq.setOnCheckedChangeListener(null);
        spf_zq_d.setOnCheckedChangeListener(null);
        zjq_zq.setOnCheckedChangeListener(null);
        zjq_zq_d.setOnCheckedChangeListener(null);
        bqc_zq.setOnCheckedChangeListener(null);
        bqc_zq_d.setOnCheckedChangeListener(null);
        bf_zq.setOnCheckedChangeListener(null);
        bf_zq_d.setOnCheckedChangeListener(null);
        hg_zq.setOnCheckedChangeListener(null);
        spf_zq.setChecked(false);
        spf_zq_d.setChecked(false);
        zjq_zq.setChecked(false);
        zjq_zq_d.setChecked(false);
        bqc_zq.setChecked(false);
        bqc_zq_d.setChecked(false);
        bf_zq.setChecked(false);
        bf_zq_d.setChecked(false);
        hg_zq.setChecked(false);
        spf_zq.setOnCheckedChangeListener(this);
        spf_zq_d.setOnCheckedChangeListener(this);
        hg_zq.setOnCheckedChangeListener(this);
        zjq_zq.setOnCheckedChangeListener(this);
        zjq_zq_d.setOnCheckedChangeListener(this);
        bqc_zq.setOnCheckedChangeListener(this);
        bqc_zq_d.setOnCheckedChangeListener(this);
        bf_zq.setOnCheckedChangeListener(this);
        bf_zq_d.setOnCheckedChangeListener(this);

    }


    public void setOnWFCheckChangedListener(OnWFCheckChangedListener listener) {
        this.listener = listener;
    }


    private OnWFCheckChangedListener listener = null;

    public interface OnWFCheckChangedListener {
        void onWFCheckChange(int id, boolean isChecked);
    }

    @Override
    public void showAtLocation(View parent, int gravity, int x, int y) {
        super.showAsDropDown(parent);
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        clearChecked();
        buttonView.setOnCheckedChangeListener(null);
        buttonView.setChecked(isChecked);
        buttonView.setOnCheckedChangeListener(this);
        if (listener != null) {
            listener.onWFCheckChange(buttonView.getId(), isChecked);
        }
        //已选中的玩法CheckBox 不能再点击
        spf_zq.setEnabled(!spf_zq.isChecked());
        spf_zq_d.setEnabled(!spf_zq_d.isChecked());
        zjq_zq.setEnabled(!zjq_zq.isChecked());
        zjq_zq_d.setEnabled(!zjq_zq_d.isChecked());
        bqc_zq.setEnabled(!bqc_zq.isChecked());
        bqc_zq_d.setEnabled(!bqc_zq_d.isChecked());
        bf_zq.setEnabled(!bf_zq.isChecked());
        bf_zq_d.setEnabled(!bf_zq_d.isChecked());
        hg_zq.setEnabled(!hg_zq.isChecked());
    }

}
